var com = require("../../utils/util.js");

const app = getApp()

// pages/myInstruction/myInstruction.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    pageSize:10,
    pageNo:1,
    userName:'',
    problemImg:[],
    problemList:[],
    matterImg:[],
    matterList:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        console.log(res.data)
        that.setData({
          userName: res.data.name
        })
      },
    })
    console.log(this.data.userName)
    //问题列表
    app.thirdScript.http.post('project/assigned/questionlist', {
      pageSize: this.data.pageSize,
      pageNo: this.data.pageNo,
      userName: this.data.userName
    }, 'set', this)
    this.matter()
  },
  set:function (res) {
    // console.log(res)
    if(res.code==200){
      if(res.message=="获取项目列表成功"){
        var imageUrl = "http://36.33.216.250:8060/zdxm/file/projectFile/";
        for(var i=0;i<res.content.list.length;i++){
          // console.log(res.content.list.length)
          // console.log(imageUrl)
          // console.log(res.content.list[i].problemUrl)
           var url=imageUrl+res.content.list[i].problemUrl
          res.content.list[i].problemUrl=url
          this.data.problemImg.push(res.content.list[i])
        }
        this.setData({
          problemList: this.data.problemImg  
        })
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }
    }
    console.log(this.data.problemList)
      },
   //事项列表
   matter:function(){
    com.post('project/assigned/list', {
      pageSize: this.data.pageSize,
      pageNo: this.data.pageNo,
      userName: this.data.userName
    }, 'get', this)
   }, 
  get:function (res) {
    console.log(res)
    if(res.code==200){
      if(res.message=="获取项目列表成功"){
        var imageUrl = "http://36.33.216.250:8060/zdxm/file/projectFile/";
        for (var i = 0; i < res.content.list.length; i++) {
          var url = imageUrl + res.content.list[i].problemUrl
          res.content.list[i].problemUrl = url
          this.data.matterImg.push(res.content.list[i])
        }
        this.setData({
          matterList: this.data.matterImg
        })
      }
    }
  },
  //获取当前index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    app.thirdScript.http.post('project/assigned/questionlist', {
      pageSize: this.data.pageSize,
      pageNo: this.data.pageNo,
      userName: this.data.userName
    }, 'set', this)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})